<!--
 * @description  : 证件-指派核查人
 * @descriptionDetail: 证件-指派核查人
 * @copyright    : 浙江烟草
 * @author       : sy
 * @create       : 2022-09-02 15:29:13
-->
<template>
  <view class="pages">
    <!-- #ifdef H5-ONLY -->
    <theme-navbar
      :is-white="false"
      :title="obj.stepType === 'recheck' ? '指派复核人' : navTitle"
      :custom-back="goBack"
      back-text="返回"
      style="z-index: 99999"
    >
    </theme-navbar>
    <!-- #endif -->
    <view class="key-search-lay">
      <u-search
        class="key-search"
        shape="round"
        :clearabled="true"
        :showAction="true"
        actionText="确定"
        :animation="true"
        placeholder="请输入姓名"
        v-model="searchKey"
        @custom="init"
      ></u-search>
    </view>
    <view class="list-content">
      <view class="space-gap">
        <u-gap :height="$theme.cm_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
      </view>
      <view class="content u-page" v-for="(item,index) in auditorList" :key="index" @tap="handlerSelectItem(item)">
        <u-row :gutter="16">
          <u-col :span="10">
            <view class="mi_content">
              <u-row :gutter="16">
                <u-col :span="5">
                  姓名:{{ item.personName }}
                </u-col>
                <u-col :span="7">
                  联系电话:{{ item.phone }}
                </u-col>
              </u-row>
            </view>
            <view class="mi_content">
              <u-row :gutter="16">
                <u-col :span="12">
                  所属部门:{{ item.deptName }}
                </u-col>
              <!-- <u-col :span="7">
                所属单位:{{ item.orgName }}
              </u-col> -->
            </u-row>
          </view>
        </u-col>
        <u-col :span="2" text-align="center">
          <u-icon
            name="checkbox-mark"
            color="#2979ff"
            size="38"
            style="margin-right: 10px;"
            v-if="brandIdList.includes(item.personId)"
          ></u-icon>
        </u-col>
      </u-row>
      <u-line color="#beb8b2" />
    </view>
    </view>
    <view class="submit-btns btn-other-cls">
      <u-button class="u-btn" type="primary" @click="submitAud()">
        确定
        <u-toast ref="uToast" />
      </u-button>
    </view>
  </view>
</template>

<script>
import certificateService from "@/service/certificate/certificate.service.js";
import {LOG_STATUS,LOG_OP_TYPE,} from '@/service/common/mapping/enum.js';
import commonService from "@/service/common/common.service.js";
export default {
  data(){
    return{
      auditorList:[],
      brandIdList:[],
      brandNameList:[],
      obj:{},
      presonId:"",
      searchKey:'',
    }
  },
  onLoad(opt){
    let list = this.getRouteParam();
    this.obj = list
  },
  mounted(){
    this.init()
  },
  methods:{
    init(){
      let param = {
        page:1,
        limit:10,
        gfCode: "sitecheck",
        stepCode: "sitecheck",
        bizId: "",
        scope: 1,
        roles: "SGY",
        inspectType: "SGY",
        personName:this.searchKey,
      }
      certificateService.entryFieldAuditDoc(param).then(res => {
        if(res.success){
          console.log(res)
          this.auditorList = res.data
        }
      }).catch(err => {
        console.log(err)
      })
    },
    handlerSelectItem(data){
      let selectItems = this.brandNameList.filter(item => { return item.personId == data.personId })
      if(selectItems.length > 0){
        this.brandNameList = this.brandNameList.filter(s => s.personId != data.personId);
        this.brandIdList = this.brandIdList.filter(i => i != data.personId);
      } else {
        this.brandNameList.push(data);
        this.brandIdList.push(data.personId);
      }
    },
    submitAud(){
      // 实地核查-最后会签人选择复审人场景
      const tip = this.obj.stepType === 'recheck' ? '一' : '两';
      const len = this.obj.stepType === 'recheck' ? 1 : 2;
      if (this.brandIdList.length !== len) {
        this.$u.toast(`必须选${tip}人`);
        return;
      }
      this.presonId = this.brandIdList.join(',')
      let docInfo = this.obj.data[0].configIns;
      let submitParams = {
        docUuid:docInfo.docUuid,
        docInsUuid:docInfo.docInsUuid,
        titemUuid:docInfo.titemUuid,
        gfaCode:"assigntask",
        nextPersons:this.presonId,
        approveInfo:'实地核查结束',
        approveDate:this.$u.timeFormat( Date.now(),'yyyy年mm月dd日'),
        approvePersonUuid:this.$storage.get(this.$rp.common.USER).user.personUuid,
        isAgree:1,
        taskId:'',
      }
      console.log(submitParams);
      this.$modal.showLoading("提交中...");
      certificateService.submitFieldAuditDoc(this.obj.bean,submitParams).then((doc) => {
        this.$modal.hideLoading();
        if(doc.success){
          this.$u.toast("提交成功");
          this.saveBehaviorLog1(LOG_OP_TYPE.submitDoc, this.obj.data[0]);
          this.backPrev({
            paramKey: "queryInfo",
            param : {tabIndex:0,}, 
          },2);
        }else{
          this.$u.toast(doc.msg);
        }
        
      }).catch((err) => {
        this.$modal.hideLoading();
        this.$u.toast(err.msg);
      });
    },
    /**
	 * @param {Boolean} status 提交还是保存
	 */
    saveBehaviorLog1(status, doc){
      commonService.getCurrentTime().then(res2 => {
        let param = {
          bizUuid: doc.bizUuid,
          docUuid:doc.docUuid,
          docInsUuid: doc.docInsUuid, 
          bizType:LOG_STATUS.B008,
          operationType: status,
          beginTime: this.obj.beginTime,
          endTime: res2.success ? res2.msg : this.$u.timeFormat(Date.now(), 'yyyy-mm-dd hh:MM:ss'),
          remark: doc.configIns.docName,
        };
        commonService.saveBehaviorLog(param).then(res => {
          console.log(res);
        }).catch(e => {
          console.log(e);
        });
      });
    },
  },
}
</script>

<style lang="scss" scoped>
.content{
  background-color: #ffffff;
	padding-left: 14rpx;
  .mi_content{
    padding: 16rpx 0 16rpx 0;
  }
}
.list-content{
  padding-bottom: 80px;
  padding-top: 50px;
}
.btn{
  position: fixed;
	bottom: 50rpx;
	margin: auto;
	left: 60rpx;
	right: 60rpx;
  z-index: 100;
  background-color: #ffffff;
}
.key-search-lay {
  background-color: #fff;
  position: fixed;
  /* #ifdef H5-DINGDING  */
  top: 0px;
  /* #endif */
  /* #ifndef H5-DINGDING  */
  top: 44px;
  /* #endif */
  z-index: 999;
  width: 100%;
  overflow: hidden;
}
.key-search {
  padding: 10px;
}
</style>